package com.bzframework.core.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;

/**
 * @Author bingzhong
 * @Date 2025/11/2
 */
public class MybatisPlusDefaultTimeHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        long currentTimeMillis = System.currentTimeMillis();
        // 插入时自动填充
        this.strictInsertFill(metaObject, "createTime", Long.class, currentTimeMillis);
        this.strictInsertFill(metaObject, "updateTime", Long.class, currentTimeMillis);
    }

    @Override
    public void updateFill(MetaObject metaObject) {

        // 更新时自动填充
        this.strictUpdateFill(metaObject, "updateTime", Long.class, System.currentTimeMillis());

    }
}
